const Base = require("./base");
module.exports = class NewsService extends Base {
  daily(params) {
    // const sql = `SELECT id,title,second_title,cover,online_time FROM news
    //   WHERE type="${params.type}" AND online_time>=DATE_SUB(NOW(), INTERVAL 1 MONTH) AND TO_DAYS(online_time)<=TO_DAYS(NOW())`;
    // 随机31条数据
    const sql = `SELECT id,title,second_title,cover,online_time FROM news WHERE type="${params.type}" ORDER BY RAND() LIMIT 32`;
    return this.app.mysql
      .use("foindia")
      .query(sql)
      .then((res) => res[0]);
  }

  recommend(params) {
    return this.app.mysql
      .use("foindia")
      .query(
        `SELECT id,title,second_title,cover,online_time FROM news WHERE type="${params.type}" ORDER BY RAND() LIMIT 10`
      )
      .then((res) => res[0]);
  }
};
